import Vue from "vue"
import VueRouter from "vue-router"

Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    routes: [{
            path: "/",
            redirect: "/index"
        },
        {
            path: '/index',
            component: () => import("@/views/Index"),
            redirect: "/index/hot",
            children: [{
                    path: 'hot',
                    component: () => import('@/views/Hot')
                },
                {
                    path: 'wait',
                    component: () => import('@/views/Wait')
                }

            ]
        },
        {
            path: '/cinema',
            component: () => import("@/views/Cinema")
        },
        {
            path: '/content',
            component: () => import("@/views/Content")
        },
        {

            path: '/index/hot/:id',
            component: () => import('@/views/Detail')
        },
        {
            path: '/index/wait/:id',
            component: () => import('@/views/Detail')
        },
        {
            path: '/city',
            component: () => import('@/views/City')
        },
        {
            path: '/login',
            component: () => import('@/views/Login')
        },
        { 
            path:'/cinemadetails',
            component:() =>import('@/views/Cinema/CinemaDetail')
        },
    ]
})
router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        next()
        return
    }
    let token = window.sessionStorage.getItem('token')
    if (token) {
        next()
        return
    }
    next('/login')
})
export default router